set matsize 11000 
 
* ) Insert directory
cd ""
use "Author-paper-referee level data", clear

***************************************
global refchars referee_Female referee_USNEWS_1 referee_USNEWS_2 referee_USNEWS_3 referee_yearsPhD ///
	referee_published_papers referee_published_from_5_no_pp referee_is_nber referee_employmentrank1 referee_employmentrank2 referee_employmentrank3 ///
	referee_employmentrank4 referee_degree_1

global authorcontrols avg* numAuthors

sum $authorcontrols

* ) Top-coding distance and include missing
replace referee_distance_min = 6 if referee_distance_min>6 | referee_distance_min==.
replace editor_distance_min = 6 if editor_distance_min>6 | editor_distance_min==.

*) When doing editor analysis, don't double count observations due to referee assignment
bysort ms_number_id editor_id: gen indicate = 1 if _n==1

gen inter_top10school = RR*referee_USNEWS_1
gen inter_referee_USNEWS_2 = RR*referee_USNEWS_2
gen inter_referee_USNEWS_3 = RR*referee_USNEWS_3
gen inter_yearsPhD = RR*referee_yearsPhD
gen inter_T5 = RR*referee_published_from_5_no_pp
gen inter_NBER = RR*referee_is_nber
gen inter_employmentrank1 = RR*referee_employmentrank1
gen inter_employmentrank2 = RR*referee_employmentrank2
gen inter_employmentrank3 = RR*referee_employmentrank3
gen inter_employmentrank4 = RR*referee_employmentrank4

* ) Author-reviewer matches
gen reviewerXphdmatch = referee_phdmatch*RR
label var reviewerXphdmatch "\underline{Positive review interact with}: \\ \ \ X Exact same PhD institution"
gen reviewerXemploymentmatch = referee_employmentmatch*RR
label var reviewerXemploymentmatch "\ \ X Former/current colleagues"
gen reviewerXisnbermatch = referee_isnbermatch_program*RR
label var reviewerXisnbermatch "\ \ X Same NBER program(s)"
gen reviewerXdistance1 = referee_distance_raw1*RR
label var reviewerXdistance1 "\ \ X Degrees of separation: 1"
gen reviewerXdistance2 = referee_distance_raw2*RR
label var reviewerXdistance2 "\ \ X Degrees of separation: 2"
gen reviewerXdistance3 = referee_distance_raw3*RR
label var reviewerXdistance3 "\ \ X Degrees of separation: 3"

gen reviewer1XRR = referee_Nconnections_raw2*RR
gen reviewer2XRR = referee_Nconnections_raw3*RR
label var reviewer1X "Total \# of direct matches to author(s): \\ \ \ \ X One match"
label var reviewer2X "\ \ \ X Two+ matches"

* ) Outcome variable - Any acceptance
gen accept = (status=="Accepted")

********************
reghdfe accept RR $refchars $authorcontrols, absorb(editor_id) vce(cluster ms_number_id)	
gen in_model_1 = e(sample)

*Editor - Connectivity
eststo clear

eststo: reghdfe accept RR $refchars $authorcontrols if in_model_1==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local papercontrols "X", replace
estadd local refcontrols "X", replace
estadd local editorFE "X",replace

eststo: reghdfe accept RR reviewerXphdmatch $refchars $authorcontrols if in_model_1==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local papercontrols "X", replace
estadd local refcontrols "X", replace
estadd local editorFE "X",replace
eststo: reghdfe accept RR reviewerXemploymentmatch $refchars $authorcontrols if in_model_1==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local papercontrols "X", replace
estadd local refcontrols "X", replace
estadd local editorFE "X",replace
eststo: reghdfe accept RR reviewerXisnbermatch $refchars $authorcontrols if in_model_1==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local papercontrols "X", replace
estadd local refcontrols "X", replace
estadd local editorFE "X",replace
eststo: reghdfe accept RR reviewerXdistance1-reviewerXdistance3 $refchars $authorcontrols if in_model_1==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local papercontrols "X", replace
estadd local refcontrols "X", replace
estadd local editorFE "X",replace
eststo: reghdfe accept RR reviewerXphdmatch reviewerXemploymentmatch reviewerXisnbermatch reviewerXdistance1-reviewerXdistance3 $refchars $authorcontrols if in_model_1==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local papercontrols "X", replace
estadd local refcontrols "X", replace
estadd local editorFE "X",replace

eststo: reghdfe accept RR reviewer1X reviewer2X $refchars $authorcontrols if in_model_1==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local papercontrols "X", replace
estadd local refcontrols "X", replace
estadd local editorFE "X",replace

label var RR "Positive review"
label var inter_top10school "Institution of PhD (IDEAS): \\ \ \ \ X Ranked top 10"
label var inter_referee_USNEWS_2 "\ \ \ X Ranked 11-30"
label var inter_referee_USNEWS_3 "\ \ \ X Ranked 31-50"
label var inter_yearsPhD "X Years since PhD"
label var inter_T5 "X \# prior top fives"
label var inter_NBER "X NBER affiliated"
label var inter_employmentrank1 "Department rank (IDEAS): \\ \ \ \ X Ranked top 10"
label var inter_employmentrank2 "\ \ \ X Ranked 11-30"
label var inter_employmentrank3 "\ \ \ X Ranked 31-100"
label var inter_employmentrank4 "\ \ \ X Ranked 101-250"

esttab using "trustreviewer.tex", ///
    replace se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) nonotes noconstant nogaps noobs nonum  ///
	mgroups("Editor accepts manuscript", pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	s(N editorFE papercontrols refcontrols r2, label("Reviewer-papers" "Editor FE" "Author controls" "Reviewer controls" "R-squared") fmt(%12.0f %12.3f)) ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)" "(10)" "(11)" "(12)") label keep(RR reviewer1XRR reviewer2XRR reviewerX*)
